from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-02-12 14:05:18.298664
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 12, Feb, 2022
Time: 14:05:24
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.0885
Nobs: 565.000 HQIC: -48.5097
Log likelihood: 6654.86 FPE: 6.53756e-22
AIC: -48.7793 Det(Omega_mle): 5.58266e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.348057 0.068847 5.056 0.000
L1.Burgenland 0.106698 0.041900 2.546 0.011
L1.Kärnten -0.111016 0.021767 -5.100 0.000
L1.Niederösterreich 0.194486 0.087532 2.222 0.026
L1.Oberösterreich 0.128956 0.086351 1.493 0.135
L1.Salzburg 0.254311 0.044296 5.741 0.000
L1.Steiermark 0.036025 0.058409 0.617 0.537
L1.Tirol 0.100112 0.047128 2.124 0.034
L1.Vorarlberg -0.071401 0.041645 -1.715 0.086
L1.Wien 0.020958 0.076707 0.273 0.785
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.055557 0.148928 0.373 0.709
L1.Burgenland -0.040656 0.090637 -0.449 0.654
L1.Kärnten 0.041042 0.047085 0.872 0.383
L1.Niederösterreich -0.200838 0.189346 -1.061 0.289
L1.Oberösterreich 0.459491 0.186792 2.460 0.014
L1.Salzburg 0.281503 0.095819 2.938 0.003
L1.Steiermark 0.113665 0.126349 0.900 0.368
L1.Tirol 0.304396 0.101947 2.986 0.003
L1.Vorarlberg 0.023559 0.090084 0.262 0.794
L1.Wien -0.027904 0.165931 -0.168 0.866
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.197474 0.035094 5.627 0.000
L1.Burgenland 0.090545 0.021358 4.239 0.000
L1.Kärnten -0.007346 0.011095 -0.662 0.508
L1.Niederösterreich 0.235142 0.044619 5.270 0.000
L1.Oberösterreich 0.165748 0.044017 3.766 0.000
L1.Salzburg 0.039817 0.022579 1.763 0.078
L1.Steiermark 0.026488 0.029774 0.890 0.374
L1.Tirol 0.082343 0.024023 3.428 0.001
L1.Vorarlberg 0.054966 0.021228 2.589 0.010
L1.Wien 0.116587 0.039101 2.982 0.003
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.121433 0.035181 3.452 0.001
L1.Burgenland 0.043445 0.021411 2.029 0.042
L1.Kärnten -0.013200 0.011123 -1.187 0.235
L1.Niederösterreich 0.170532 0.044729 3.813 0.000
L1.Oberösterreich 0.335833 0.044126 7.611 0.000
L1.Salzburg 0.100007 0.022635 4.418 0.000
L1.Steiermark 0.110280 0.029847 3.695 0.000
L1.Tirol 0.090252 0.024083 3.748 0.000
L1.Vorarlberg 0.060579 0.021281 2.847 0.004
L1.Wien -0.019272 0.039198 -0.492 0.623
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.124035 0.066247 1.872 0.061
L1.Burgenland -0.048112 0.040318 -1.193 0.233
L1.Kärnten -0.045551 0.020945 -2.175 0.030
L1.Niederösterreich 0.139687 0.084226 1.658 0.097
L1.Oberösterreich 0.163856 0.083090 1.972 0.049
L1.Salzburg 0.283705 0.042623 6.656 0.000
L1.Steiermark 0.057545 0.056203 1.024 0.306
L1.Tirol 0.156171 0.045349 3.444 0.001
L1.Vorarlberg 0.095289 0.040072 2.378 0.017
L1.Wien 0.076539 0.073810 1.037 0.300
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.080974 0.051693 1.566 0.117
L1.Burgenland 0.024993 0.031460 0.794 0.427
L1.Kärnten 0.053284 0.016343 3.260 0.001
L1.Niederösterreich 0.191451 0.065722 2.913 0.004
L1.Oberösterreich 0.328772 0.064836 5.071 0.000
L1.Salzburg 0.033704 0.033259 1.013 0.311
L1.Steiermark 0.005500 0.043856 0.125 0.900
L1.Tirol 0.120365 0.035386 3.402 0.001
L1.Vorarlberg 0.065557 0.031268 2.097 0.036
L1.Wien 0.097318 0.057595 1.690 0.091
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.170775 0.062454 2.734 0.006
L1.Burgenland 0.003525 0.038009 0.093 0.926
L1.Kärnten -0.065970 0.019745 -3.341 0.001
L1.Niederösterreich -0.109363 0.079403 -1.377 0.168
L1.Oberösterreich 0.210822 0.078332 2.691 0.007
L1.Salzburg 0.053227 0.040182 1.325 0.185
L1.Steiermark 0.249320 0.052985 4.705 0.000
L1.Tirol 0.499452 0.042752 11.683 0.000
L1.Vorarlberg 0.065029 0.037777 1.721 0.085
L1.Wien -0.073590 0.069584 -1.058 0.290
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.160219 0.069171 2.316 0.021
L1.Burgenland -0.004785 0.042097 -0.114 0.910
L1.Kärnten 0.062273 0.021869 2.848 0.004
L1.Niederösterreich 0.176151 0.087943 2.003 0.045
L1.Oberösterreich -0.062242 0.086757 -0.717 0.473
L1.Salzburg 0.205924 0.044504 4.627 0.000
L1.Steiermark 0.138358 0.058684 2.358 0.018
L1.Tirol 0.056599 0.047350 1.195 0.232
L1.Vorarlberg 0.143831 0.041840 3.438 0.001
L1.Wien 0.127104 0.077068 1.649 0.099
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.392831 0.040571 9.682 0.000
L1.Burgenland -0.002791 0.024692 -0.113 0.910
L1.Kärnten -0.021401 0.012827 -1.668 0.095
L1.Niederösterreich 0.200064 0.051582 3.879 0.000
L1.Oberösterreich 0.230816 0.050886 4.536 0.000
L1.Salzburg 0.036526 0.026103 1.399 0.162
L1.Steiermark -0.017225 0.034420 -0.500 0.617
L1.Tirol 0.091261 0.027773 3.286 0.001
L1.Vorarlberg 0.051367 0.024541 2.093 0.036
L1.Wien 0.041481 0.045203 0.918 0.359
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.035540 0.105755 0.168444 0.134799 0.095862 0.081404 0.030063 0.212823
Kärnten 0.035540 1.000000 -0.025836 0.132322 0.047255 0.085463 0.444056 -0.067992 0.090366
Niederösterreich 0.105755 -0.025836 1.000000 0.312627 0.123974 0.270714 0.065977 0.156599 0.284077
Oberösterreich 0.168444 0.132322 0.312627 1.000000 0.214207 0.293602 0.167908 0.135058 0.235874
Salzburg 0.134799 0.047255 0.123974 0.214207 1.000000 0.124049 0.091023 0.103533 0.127185
Steiermark 0.095862 0.085463 0.270714 0.293602 0.124049 1.000000 0.134149 0.105672 0.031366
Tirol 0.081404 0.444056 0.065977 0.167908 0.091023 0.134149 1.000000 0.063289 0.152174
Vorarlberg 0.030063 -0.067992 0.156599 0.135058 0.103533 0.105672 0.063289 1.000000 -0.003786
Wien 0.212823 0.090366 0.284077 0.235874 0.127185 0.031366 0.152174 -0.003786 1.000000